//页面一加载就显示
function findAllBank() {
	var lujing = getPath() + '/Bank';

	$.ajax({
		type: 'post',
		url: lujing,
		async: true,
		dataType: 'json',
		data: {
			"method": "findAllBank",
			"cur": "1",
			"ps": "3",
		},
		success: function(jsonDate) {
			//console.log(jsonData);
			console.log(jsonDate.result);
			var bankLists = jsonDate.bankLists;
			$(bankLists).each(function(index, data) {
				var bankId = data.id;
				//console.log(bankId);
				var bankName = data.bankName;
				var bankPhone = data.bankPhone;
				var bankAddress = data.bankAddress;

				var checkboxtd = $('<td><input type="checkbox"  id="' + bankId + '"/></td>');
				var nametd = $('<td>' + bankName + '</td>');
				var phonetd = $('<td>' + bankPhone + '</td>');
				var addresstd = $('<td>' + bankAddress + '</td>');

				var tr = $('<tr class="bootstrap"></tr>');

				tr.append(checkboxtd);
				tr.append(nametd);
				tr.append(phonetd);
				tr.append(addresstd);

				$('#tb').append(tr);
			});

		}
	});
}
//添加
$('#addConfirm').click(function() {
	var lujing = getPath() + '/Bank';

	var bankName = $('input[name="bankName1"]').val();
	var bankPhone = $('input[name="bankPhone1"]').val();
	var bankAddress = $('input[name="bankAddress1"]').val();

	$.ajax({
		type: 'post',
		url: lujing,
		async: true,
		dataType: 'json',
		data: {
			"method": "addBank",
			"bankName": bankName,
			"bankPhone": bankPhone,
			"bankAddress": bankAddress,
		},
		success: function(jsonDate) {
			//console.log(jsonData);
			//var bankEntity=jsonDate.bankEntity;
			//console.log(bankEntity.bankName)
			$('tr.bootstrap').empty();
			findAllBank();
		}
	});
})

//修改1
$('#up').click(function() {
	var lujing = getPath() + '/Bank';

	var updateId = $('input[type="checkbox"]:checked');
	//console.log(deleteId);
	/*var upStr='';
	updateId.each(function(index,data){
		upStr+=$(data).attr('id')+',';
	});
	upStr=upStr.substring(0,upStr.length-1);
	console.log(upStr);*/
	var upStr = updateId.attr('id');
	console.log(upStr);

	$.ajax({
		type: 'post',
		url: lujing,
		async: true,
		dataType: 'json',
		data: {
			"method": "updateBank",
			"upStr": upStr,
		},
		success: function(jsonData) {
			var bankEntity = jsonData.bankEntity;
			//console.log(bankEntity.bankName);
			var bankId = bankEntity.id;
			var bankName = bankEntity.bankName;
			var bankPhone = bankEntity.bankPhone;
			var bankAddress = bankEntity.bankAddress;

			$('input[name="bankName2"]').attr('class', bankId);
			$('input[name="bankName2"]').val(bankName);
			$('input[name="bankPhone2"]').val(bankPhone);
			$('input[name="bankAddress2"]').val(bankAddress);

			
		}

	});
})

//修改2
$('#upConfirm').click(function() {
	console.log('+++');
	var lujing = getPath() + '/Bank';

	var bankId = $('input[name="bankName2"]').attr('class');
	var bankName = $('input[name="bankName2"]').val();
	var bankPhone = $('input[name="bankPhone2"]').val();
	var bankAddress = $('input[name="bankAddress2"]').val();
	
	console.log(bankId);
	console.log(bankName);
	console.log(bankPhone);
	console.log(bankAddress);

	$.ajax({
		type: 'post',
		url: lujing,
		async: true,
		dataType: 'json',
		data: {
			"method": "updateBank1",
			"bankId": bankId,
			"bankName": bankName,
			"bankPhone": bankPhone,
			"bankAddress": bankAddress,
		},
		success: function(jsonDate) {
			console.log(jsonDate.result)
			//console.log(jsonData);
			//var bankEntity=jsonDate.bankEntity;
			//console.log(bankEntity.bankName)
			$('tr.bootstrap').empty();
			findAllBank();
		}
	});
})

$('#del').click(function(){
	var lujing = getPath() + '/Bank';

	var deleteId = $('input[type="checkbox"]:checked');
	
	var delStr = deleteId.attr('id');
	//console.log(delStr);

	$.ajax({
		type: 'post',
		url: lujing,
		async: true,
		dataType: 'json',
		data: {
			"method": "deleteBank",
			"delStr": delStr,
		},
		success: function(jsonData) {
			$('tr.bootstrap').empty();
			findAllBank();
			
		}

	});
})